]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
src: Stop using g_get_current_time()
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 31 Jul 2019 18:29:46 +0000 (20:29 +0200)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Fri, 9 Aug 2019 19:22:18 +0000 (19:22 +0000)
It isn't 2k38 safe and has therefore been deprecated. Replace it
with GDateTime or g_get_real_time() as appropriate.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/657

src/calendar-server/gnome-shell-calendar-server.c
src/hotplug-sniffer/hotplug-sniffer.c
src/shell-app-usage.c
src/shell-polkit-authentication-agent.c

index d5b6e01f7beb7d659f1b6e5ac69efaa3cdc9dcb8..2da4d113ae4b911a957b637734045a94bd43f960 100644 (file)
@@ -1102,12 +1102,10 @@ main (int    argc,
 static void __attribute__((format(printf, 1, 0)))
 print_debug (const gchar *format, ...)
 {
-  gchar *s;
+  g_autofree char *s = NULL;
+  g_autofree char *timestamp = NULL;
   va_list ap;
-  gchar timebuf[64];
-  GTimeVal now;
-  time_t now_t;
-  struct tm broken_down;
+  g_autoptr (GDateTime) now = NULL;
   static volatile gsize once_init_value = 0;
   static gboolean show_debug = FALSE;
   static guint pid = 0;
@@ -1122,17 +1120,15 @@ print_debug (const gchar *format, ...)
   if (!show_debug)
     goto out;
 
-  g_get_current_time (&now);
-  now_t = now.tv_sec;
-  localtime_r (&now_t, &broken_down);
-  strftime (timebuf, sizeof timebuf, "%H:%M:%S", &broken_down);
+  now = g_date_time_new_now_local ();
+  timestamp = g_date_time_format (now, "%H:%M:%S");
 
   va_start (ap, format);
   s = g_strdup_vprintf (format, ap);
   va_end (ap);
 
-  g_print ("gnome-shell-calendar-server[%d]: %s.%03d: %s\n", pid, timebuf, (gint) (now.tv_usec / 1000), s);
-  g_free (s);
+  g_print ("gnome-shell-calendar-server[%d]: %s.%03d: %s\n",
+           pid, timestamp, g_date_time_get_microsecond (now), s);
  out:
   ;
 }
index 31e45795ed43f262d583d5f0d36946ee7cf34c01..b8d7fa0ea8e28b4b1aa34f36c0d72370a174229f 100644 (file)
@@ -269,12 +269,10 @@ main (int    argc,
 static void __attribute__((format(printf, 1, 0)))
 print_debug (const gchar *format, ...)
 {
-  gchar *s;
+  g_autofree char *s = NULL;
+  g_autofree char *timestamp = NULL;
   va_list ap;
-  gchar timebuf[64];
-  GTimeVal now;
-  time_t now_t;
-  struct tm broken_down;
+  g_autoptr (GDateTime) now = NULL;
   static volatile gsize once_init_value = 0;
   static gboolean show_debug = FALSE;
   static guint pid = 0;
@@ -289,17 +287,15 @@ print_debug (const gchar *format, ...)
   if (!show_debug)
     goto out;
 
-  g_get_current_time (&now);
-  now_t = now.tv_sec;
-  localtime_r (&now_t, &broken_down);
-  strftime (timebuf, sizeof timebuf, "%H:%M:%S", &broken_down);
+  now = g_date_time_new_now_local ();
+  timestamp = g_date_time_format (now, "%H:%M:%S");
 
   va_start (ap, format);
   s = g_strdup_vprintf (format, ap);
   va_end (ap);
 
-  g_print ("gnome-shell-hotplug-sniffer[%d]: %s.%03d: %s\n", pid, timebuf, (gint) (now.tv_usec / 1000), s);
-  g_free (s);
+  g_print ("gnome-shell-hotplug-sniffer[%d]: %s.%03d: %s\n",
+           pid, timestamp, g_date_time_get_microsecond (now), s);
  out:
   ;
 }
index b8dc768cae81309b2d2cfd54153e02fc49f32607..b8c3e75674767866bdfa81a12c8679aafffdd207 100644 (file)
@@ -123,9 +123,7 @@ static void on_enable_monitoring_key_changed (GSettings     *settings,
 static long
 get_time (void)
 {
-  GTimeVal tv;
-  g_get_current_time (&tv);
-  return tv.tv_sec;
+  return g_get_real_time () / G_TIME_SPAN_SECOND;
 }
 
 static void
index bca967fa1beaf9377fa4ffd1f08b049d6f5542f9..6815f01aff25185f19944f91938ea1da243e62de 100644 (file)
 static void
 print_debug (const gchar *format, ...)
 {
-  gchar *s;
+  g_autofree char *s = NULL;
+  g_autofree char *timestamp = NULL;
+  g_autoptr (GDateTime) now = NULL;
   va_list ap;
-  gchar timebuf[64];
-  GTimeVal now;
-  time_t now_t;
-  struct tm broken_down;
 
-  g_get_current_time (&now);
-  now_t = now.tv_sec;
-  localtime_r (&now_t, &broken_down);
-  strftime (timebuf, sizeof timebuf, "%H:%M:%S", &broken_down);
+  now = g_date_time_new_now_local ();
+  timestamp = g_date_time_format (now, "%H:%M:%S");
 
   va_start (ap, format);
   s = g_strdup_vprintf (format, ap);
   va_end (ap);
 
-  g_print ("ShellPolkitAuthenticationAgent: %s.%03d: %s\n", timebuf, (gint) (now.tv_usec / 1000), s);
-  g_free (s);
+  g_print ("ShellPolkitAuthenticationAgent: %s.%03d: %s\n",
+           timestamp, g_date_time_get_microsecond (now), s);
 }
 #else
 static void